/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.action;

import com.funcom.peeler.UpdateCont;
import com.funcom.peeler.WorkBench;
import com.funcom.peeler.peelable.PeelComponent;
import com.funcom.peeler.peelable.PeelContainer;

public class Place implements Change {

    private PeelComponent component;
    private PeelContainer parent;
    WorkBench.Bui bui;

    public Place( PeelComponent component, PeelContainer parent, WorkBench.Bui bui  ) {
        if ( component == null || parent == null ) throw new NullPointerException( "Placements must use a valid component and parent" );
        this.bui = bui;
        this.component = component;
        this.parent = parent;
    }

    public void startChange() {
    }

    public void endChange() {
    }

    public void doChange() {
        if ( bui != null ) bui.select( component );
        parent.addChild( component );
        UpdateCont.get().newOrDeleteChange(true);
    }

    public void undoChange() {
        if ( bui != null ) bui.deselect( component );        
        parent.removeChild( component );
        UpdateCont.get().newOrDeleteChange(true);
    }

    public boolean valid() {
        return true;
    }
}
